package com.example.qxfw.qxzs.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.qx.*;
import com.example.qxfw.common.entity.xt.SysConfig;
import com.example.qxfw.common.entity.zy.*;
import com.example.qxfw.common.util.WeatherUtil;
import com.example.qxfw.qxzs.dto.StationYbDto;
import com.example.qxfw.qxzs.dto.ZsjsDto;
import com.example.qxfw.qxzs.service.*;
import com.example.qxfw.qxzs.dto.StationSkDto;
import com.example.qxfw.qxzs.vo.StationYbVo;
import com.example.qxfw.ybzz.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.dom4j.DocumentException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Api(tags = "指数预报-气象指数预报接口")
@RestController
@CrossOrigin
@RequestMapping("/zsyb")
public class
ZsybController {

    @Autowired
    private SysConfigService sysConfigService;

    @Autowired
    private SpecialSrvStationService specialSrvStationService;

    @Autowired
    private TownshipStationService townshipStationService;

    @Autowired
    private TownshipForecastService townshipForecastService;

    @Autowired
    private MsgMediumSmallScaleService msgMediumSmallScaleService;

    @Autowired
    private TourFcstService tourFcstService;

    @Autowired
    private TourSmallScaleService tourSmallScaleService;

    @Autowired
    private TrafficFcstService trafficFcstService;

    @Autowired
    private TrafficSmallScaleService trafficSmallScaleService;

    @Autowired
    private ZhishuSetService zhishuSetService;

    @Autowired
    private ZhishuService zhishuService;

    @Autowired
    private WeatherUtil weatherUtil;

    @Autowired
    private ZsybService zsybService;

    @ApiIgnore
    @ApiOperation("获取SysConfig")
    @GetMapping("/getSysConfig")
    public SysResult getSysConfig(String paramType) {
        List<SysConfig> list = sysConfigService.getList(paramType);
        return SysResult.success(list);
    }

    @ApiOperation("修改参数")
    @PostMapping("/updateSysConfig")
    public SysResult updateSysConfig(SysConfig sysConfig) {
        Integer rows = sysConfigService.updateByParamName(sysConfig);
        return SysResult.success(rows);
    }

    @ApiOperation("获取SpecialSrv站点")
    @GetMapping("/getSpecialSrvStation")
    public SysResult getSpecialSrvStation() {
        List<SpecialSrvStation> list = specialSrvStationService.getList();
        return SysResult.success(list);
    }

    @ApiIgnore
    @ApiOperation("根据名称获取站点信息")
    @GetMapping("/getSpecialSrvStationByName")
    public SysResult getSpecialSrvStationByName(String stationName) {
        List<SpecialSrvStation> listByName = specialSrvStationService.getListByName(stationName);
        return SysResult.success(listByName);
    }

    @ApiIgnore
    @ApiOperation("查询乡镇站点")
    @GetMapping("/getTownshipStation")
    public SysResult getTownshipStation(String jd, String wd, String city) {
        List<TownshipStation> list = townshipStationService.getList(jd, wd, city);
        return SysResult.success(list);
    }

    @ApiIgnore
    @ApiOperation("查询选中指数设置")
    @GetMapping("/getSelectZhishuSet")
    public SysResult getSelectZhishuSet() {
        Map<String, List<ZhishuSet>> stringListMap = zhishuSetService.listSelected();
        return SysResult.success(stringListMap);
    }

    @ApiIgnore
    @ApiOperation("查询未选中指数设置")
    @GetMapping("/getUnSelectZhishuSet")
    public SysResult getUnSelectZhishuSet() {
        Map<String, List<ZhishuSet>> stringListMap = zhishuSetService.listUnSelected();
        return SysResult.success(stringListMap);
    }

    @ApiIgnore
    @ApiOperation("修改指数设置")
    @PostMapping("/updateZhishuSet")
    public SysResult getZhishuSet(@RequestBody ZhishuSet zhishuSet) {
        int rows = zhishuSetService.updateById(zhishuSet);
        return SysResult.success(rows);
    }

    @ApiIgnore
    @ApiOperation("查询cityId")
    @GetMapping("/getZhishuCityId")
    public SysResult getZhishuCity(String cityName, String dateChar, String timeChar) {
        List<String> cityId = zhishuService.getCityId(cityName, dateChar, timeChar);
        return SysResult.success(cityId);
    }

    @ApiIgnore
    @ApiOperation("插入指数")
    @PostMapping("saveZhishu")
    public SysResult saveZhishu(Zhishu zhishu) {
        Integer rows = zhishuService.saveZhishu(zhishu);
        return SysResult.success(rows);
    }

    @ApiIgnore
    @ApiOperation("修改指数")
    @PostMapping("updateZhishu")
    public SysResult updateZhishu(Zhishu zhishu) {
        Integer rows = zhishuService.updateZhishu(zhishu);
        return SysResult.success(rows);
    }

    @ApiOperation("获取自动站预报数据")
    @GetMapping("/getTownshipFcst")
    public SysResult getTownshipFcst(String dateChar, String timeChar, String stationId) {
        List<TownshipForecast> list = townshipForecastService.listByParam(dateChar, timeChar, 12, 24, stationId);
        if (list.size() > 0) {
            StationYbVo stationYbVo = new StationYbVo();
            TownshipForecast fact12 = list.get(0);
            TownshipForecast fact24 = list.get(1);
            stationYbVo.setFState1(fact12.getWeather1());
            stationYbVo.setFState2(fact24.getWeather1());
            stationYbVo.setFWindDirection1(weatherUtil.GetFxIDByValue(String.valueOf(fact12.getWindd())));
            stationYbVo.setFWindDirection1(weatherUtil.GetFxIDByValue(String.valueOf(fact24.getWindd())));
            stationYbVo.setFTemperatureLow(fact12.getMintemp() < fact24.getMintemp() ? fact12.getMintemp() : fact24.getMintemp());
            stationYbVo.setFTemperatureHigh(fact12.getMaxtemp() > fact24.getMaxtemp() ? fact12.getMaxtemp() : fact24.getMaxtemp());
            stationYbVo.setFWindSpeedLow(fact12.getWinds());
            stationYbVo.setFWindSpeedHigh(fact24.getWinds());
            stationYbVo.setFWetnessLow((int) Math.round(fact12.getHumid()));
            stationYbVo.setFWetnessHigh((int) Math.round(fact24.getHumid()));
            if (fact12.getPress() != null && fact24.getPress() != null) {
                stationYbVo.setFPressure((int) (fact12.getPress() + fact24.getPress()) / 2);
            }
            stationYbVo.setFCloudLow((int) Math.round(fact12.getCloudlow()));
            stationYbVo.setFCloudAll((int) Math.round(fact12.getCloud()));
            stationYbVo.setFPrecipitationrate((fact12.getRain() + fact24.getRain()) > 0 ? 100 : 0);
            stationYbVo.setFPrecipitation((int) (fact12.getRain() + fact24.getRain()));
            StationYbDto stationYbDto = new StationYbDto();
            stationYbDto.setFState1(Integer.parseInt(weatherUtil.getWeatherId(fact12.getWeather1())));
            stationYbDto.setFState2(Integer.parseInt(weatherUtil.getWeatherId(fact24.getWeather1())));

            stationYbDto.setFWindDirection1(Integer.parseInt(weatherUtil.GetFxIDByValue(String.valueOf(fact12.getWindd()))));
            stationYbDto.setFWindDirection2(Integer.parseInt(weatherUtil.GetFxIDByValue(String.valueOf(fact24.getWindd()))));
            stationYbDto.setFTemperatureLow(fact12.getMintemp() < fact24.getMintemp() ? fact12.getMintemp() : fact24.getMintemp());
            stationYbDto.setFTemperatureHigh(fact12.getMaxtemp() > fact24.getMaxtemp() ? fact12.getMaxtemp() : fact24.getMaxtemp());
            stationYbDto.setFWindSpeedLow(fact12.getWinds());
            stationYbDto.setFWindSpeedHigh(fact24.getWinds());
            stationYbDto.setFWetnessLow((int) Math.round(fact12.getHumid()));
            stationYbDto.setFWetnessHigh((int) Math.round(fact24.getHumid()));
            if (fact12.getPress() != null && fact24.getPress() != null) {
                stationYbDto.setFPressure((int) (fact12.getPress() + fact24.getPress()) / 2);
            }
            stationYbDto.setFCloudLow((int) Math.round(fact12.getCloudlow()));
            stationYbDto.setFCloudAll((int) Math.round(fact12.getCloud()));
            stationYbDto.setFPrecipitationrate((fact12.getRain() + fact24.getRain()) > 0 ? 100 : 0);
            stationYbDto.setFPrecipitation((int) (fact12.getRain() + fact24.getRain()));
            return SysResult.success(stationYbVo, stationYbDto);
        } else {
            return SysResult.success(new StationYbVo(), new StationYbDto());
        }
    }

    @ApiOperation("获取自动站实况数据")
    @GetMapping("/getMsgMediumSmallScale")
    public SysResult getMsgMediumSmallScale(String observTime1, String observTime2, String stationId) {
        List<MsgMediumSmallScale> list = msgMediumSmallScaleService.listByParam(observTime1, observTime2, stationId);
        int avgPressCount = 0;
        int avgHumidCount = 0;
        int avgTempCount = 0;
        StationSkDto stationSkVo = new StationSkDto();
        for (int i = 0; i < list.size(); i++) {
            MsgMediumSmallScale sk = list.get(i);
            if (sk.getDrybulbtemp() > -65000) {
                if (i == 0) {
                    avgTempCount = Math.round(sk.getDrybulbtemp());
                } else {
                    avgTempCount += sk.getDrybulbtemp();
                }
            }
            if (sk.getMintemp() > -65000) {
                if (i == 0) {
                    stationSkVo.setTTemperatureLow(sk.getMintemp());
                } else if (sk.getMintemp() < stationSkVo.getTTemperatureLow()) {
                    stationSkVo.setTTemperatureLow(sk.getMintemp());
                }
            }
            if (sk.getMaxtemp() > -65000) {
                if (i == 0) {
                    stationSkVo.setTTemperatureHigh(sk.getMaxtemp());
                } else if (sk.getMaxtemp() > stationSkVo.getTTemperatureHigh()) {
                    stationSkVo.setTTemperatureHigh(sk.getMaxtemp());
                }
            }

            if (sk.getRain() > -65000) {
                if (i == 0) {
                    stationSkVo.setTPrecipitation24(Math.round(sk.getRain()));
                } else {
                    stationSkVo.setTPrecipitation24(stationSkVo.getTPrecipitation24() + sk.getRain());
                }
            }
            if (sk.getStationpress() > -65000) {
                if (i == 0) {
                    stationSkVo.setTPressure(Math.round(sk.getStationpress()));
                } else {
                    stationSkVo.setTPressure(stationSkVo.getTPressure() + sk.getStationpress());
                }
            }
            if (sk.getRelhumidity() > -65000) {
                if (i == 0) {
                    stationSkVo.setTWetness(sk.getRelhumidity());
                } else {
                    stationSkVo.setTWetness(stationSkVo.getTWetness() + sk.getRelhumidity());
                }
            }
        }
        //平均温度
        if (avgTempCount > 0) {
            stationSkVo.setTTemperature((double) avgTempCount / list.size());
        }
        //平均气压
        if (stationSkVo.getTPressure() > 0) {
            stationSkVo.setTPressure(stationSkVo.getTPressure() / list.size());
        }
        //平均相对湿度
        if (stationSkVo.getTWetness() > 0) {
            stationSkVo.setTWetness(stationSkVo.getTWetness() / list.size());
        }
        //求24小时变压
        if (list.size() > 0) {
            Float maxQY = list.get(list.size() - 1).getMaxstationpress();
            Float minQY = list.get(list.size() - 1).getMinstationpress();
            //压强存在
            if (maxQY > 0 || minQY > 0) {
                stationSkVo.setTIsallo(maxQY - minQY);//实况24小时变压
            }
        }
        //14小时风向
        if (list.size() > 0) {
            int windDirect = list.get(list.size() - 1).getWinddirect();
            if (windDirect >= 0 && windDirect <= 360) {
                stationSkVo.setTWindDirection(windDirect);
            }
        }
        //实况平均总云量
        stationSkVo.setTCloudAll(0);
        return SysResult.success(stationSkVo, stationSkVo);
    }

    @ApiOperation("获取旅游预报数据")
    @GetMapping("/getTourFcst")
    public SysResult getTourFcst(String dateChar, String timeChar, String stationId) {
        List<TourFcst> list = tourFcstService.listByParam(dateChar, timeChar, 12, 24, stationId);
        if (list.size() > 0) {
            StationYbVo stationYbVo = new StationYbVo();
            TourFcst fact12 = list.get(0);
            TourFcst fact24 = list.get(1);
            stationYbVo.setFState1(fact12.getWeather1());
            stationYbVo.setFState2(fact24.getWeather1());
            stationYbVo.setFWindDirection1(weatherUtil.GetFxIDByValue(fact12.getWindd()));
            stationYbVo.setFWindDirection2(weatherUtil.GetFxIDByValue(fact24.getWindd()));
            stationYbVo.setFTemperatureLow(fact12.getMintemp() < fact24.getMintemp() ? fact12.getMintemp() : fact24.getMintemp());
            stationYbVo.setFTemperatureHigh(fact12.getMaxtemp() > fact24.getMaxtemp() ? fact12.getMaxtemp() : fact24.getMaxtemp());
            stationYbVo.setFWindSpeedLow(Double.parseDouble(fact12.getWinds()));
            stationYbVo.setFWindSpeedHigh(Double.parseDouble(fact24.getWinds()));
            stationYbVo.setFWetnessLow((int) Math.round(fact12.getHumid()));
            stationYbVo.setFWetnessHigh((int) Math.round(fact24.getHumid()));
            stationYbVo.setFCloudLow((int) Math.round(fact12.getCloudlow()));
            stationYbVo.setFCloudAll((int) Math.round(fact12.getCloud()));
            stationYbVo.setFPrecipitationrate((fact12.getRain() + fact24.getRain()) > 0 ? 100 : 0);
            stationYbVo.setFPrecipitation((int) (fact12.getRain() + fact24.getRain()));
            StationYbDto stationYbDto = new StationYbDto();
            stationYbDto.setFState1(Integer.parseInt(weatherUtil.getWeatherId(fact12.getWeather1())));

            stationYbDto.setFState2(Integer.parseInt(weatherUtil.getWeatherId(fact24.getWeather1())));

            stationYbDto.setFWindDirection1(Integer.parseInt(weatherUtil.GetFxIDByValue(fact12.getWindd())));
            stationYbDto.setFWindDirection2(Integer.parseInt(weatherUtil.GetFxIDByValue(fact24.getWindd())));
            stationYbDto.setFTemperatureLow(fact12.getMintemp() < fact24.getMintemp() ? fact12.getMintemp() : fact24.getMintemp());
            stationYbDto.setFTemperatureHigh(fact12.getMaxtemp() > fact24.getMaxtemp() ? fact12.getMaxtemp() : fact24.getMaxtemp());
            stationYbDto.setFWindSpeedLow(Double.parseDouble(fact12.getWinds()));
            stationYbDto.setFWindSpeedHigh(Double.parseDouble(fact24.getWinds()));
            stationYbDto.setFWetnessLow((int) Math.round(fact12.getHumid()));
            stationYbDto.setFWetnessHigh((int) Math.round(fact24.getHumid()));
            stationYbDto.setFCloudLow((int) Math.round(fact12.getCloudlow()));
            stationYbDto.setFCloudAll((int) Math.round(fact12.getCloud()));
            stationYbDto.setFPrecipitationrate((fact12.getRain() + fact24.getRain()) > 0 ? 100 : 0);
            stationYbDto.setFPrecipitation((int) (fact12.getRain() + fact24.getRain()));
            return SysResult.success(stationYbVo, stationYbDto);
        } else {
            return SysResult.success(new StationYbVo(), new StationYbDto());
        }

    }

    @ApiOperation("获取旅游实况数据")
    @GetMapping("/getTourSmallScale")
    public SysResult getTourSmallScale(String observTime1, String observTime2, String stationId) {
        List<TourSmallscale> list = tourSmallScaleService.listByParam(observTime1, observTime2, stationId);
        int avgPressCount = 0;
        int avgHumidCount = 0;
        int avgTempCount = 0;
        StationSkDto stationSkVo = new StationSkDto();
        for (int i = 0; i < list.size(); i++) {
            TourSmallscale sk = list.get(i);
            if (sk.getDrybulbtemp() > -65000) {
                if (i == 0) {
                    avgTempCount = Math.round(sk.getDrybulbtemp());
                } else {
                    avgTempCount += sk.getDrybulbtemp();
                }
            }
            if (sk.getMintemp() > -65000) {
                if (i == 0) {
                    stationSkVo.setTTemperatureLow(sk.getMintemp());
                } else if (sk.getMintemp() < stationSkVo.getTTemperatureLow()) {
                    stationSkVo.setTTemperatureLow(sk.getMintemp());
                }
            }
            if (sk.getMaxtemp() > -65000) {
                if (i == 0) {
                    stationSkVo.setTTemperatureHigh(sk.getMaxtemp());
                } else if (sk.getMaxtemp() > stationSkVo.getTTemperatureHigh()) {
                    stationSkVo.setTTemperatureHigh(sk.getMaxtemp());
                }
            }

            if (sk.getRain() > -65000) {
                if (i == 0) {
                    stationSkVo.setTPrecipitation24(Math.round(sk.getRain()));
                } else {
                    stationSkVo.setTPrecipitation24(stationSkVo.getTPrecipitation24() + sk.getRain());
                }
            }
            if (sk.getStationpress() > -65000) {
                if (i == 0) {
                    stationSkVo.setTPressure(Math.round(sk.getStationpress()));
                } else {
                    stationSkVo.setTPressure(stationSkVo.getTPressure() + sk.getStationpress());
                }
            }
            if (sk.getRelhumidity() > -65000) {
                if (i == 0) {
                    stationSkVo.setTWetness(sk.getRelhumidity());
                } else {
                    stationSkVo.setTWetness(stationSkVo.getTWetness() + sk.getRelhumidity());
                }
            }
        }
        //平均温度
        if (avgTempCount > 0) {
            stationSkVo.setTTemperature((double) avgTempCount / list.size());
        }
        //平均气压
        if (stationSkVo.getTPressure() > 0) {
            stationSkVo.setTPressure(stationSkVo.getTPressure() / list.size());
        }
        //平均相对湿度
        if (stationSkVo.getTWetness() > 0) {
            stationSkVo.setTWetness(stationSkVo.getTWetness() / list.size());
        }
        //求24小时变压
        if (list.size() > 0) {
            Float maxQY = list.get(list.size() - 1).getMaxstationpress();
            Float minQY = list.get(list.size() - 1).getMinstationpress();
            //压强存在
            if (maxQY > 0 || minQY > 0) {
                stationSkVo.setTIsallo(maxQY - minQY);//实况24小时变压
            }
        }
        //14小时风向
        if (list.size() > 0) {
            int windDirect = list.get(list.size() - 1).getWinddirect();
            if (windDirect >= 0 && windDirect <= 360) {
                stationSkVo.setTWindDirection(windDirect);
            }
        }
        //实况平均总云量
        stationSkVo.setTCloudAll(0);
        return SysResult.success(stationSkVo);

    }

    @ApiOperation("获取交通预报数据")
    @GetMapping("/getTrafficFcst")
    public SysResult getTrafficFcst(String dateChar, String timeChar, String stationId) {
        List<TrafficFcst> list = trafficFcstService.listByParam(dateChar, timeChar, 12, 24, stationId);
        if (list.size() > 0) {
            StationYbVo stationYbVo = new StationYbVo();
            TrafficFcst fact12 = list.get(0);
            TrafficFcst fact24 = list.get(1);
            stationYbVo.setFState1(fact12.getWeather1());
            stationYbVo.setFState2(fact24.getWeather1());
            stationYbVo.setFWindDirection1(weatherUtil.GetFxIDByValue(String.valueOf(fact12.getWindd())));
            stationYbVo.setFWindDirection1(weatherUtil.GetFxIDByValue(String.valueOf(fact24.getWindd())));
            stationYbVo.setFTemperatureLow(fact12.getMintemp() < fact24.getMintemp() ? fact12.getMintemp() : fact24.getMintemp());
            stationYbVo.setFTemperatureHigh(fact12.getMaxtemp() > fact24.getMaxtemp() ? fact12.getMaxtemp() : fact24.getMaxtemp());
            stationYbVo.setFWindSpeedLow(fact12.getWinds());
            stationYbVo.setFWindSpeedHigh(fact24.getWinds());
            stationYbVo.setFWetnessLow((int) Math.round(fact12.getHumid()));
            stationYbVo.setFWetnessHigh((int) Math.round(fact24.getHumid()));
//            stationYbVo.setFPressure((int) (fact12.getPress()+fact24.getPress())/2);
            stationYbVo.setFCloudLow((int) Math.round(fact12.getCloudlow()));
            stationYbVo.setFCloudAll((int) Math.round(fact12.getCloud()));
            stationYbVo.setFPrecipitationrate((fact12.getRain() + fact24.getRain()) > 0 ? 100 : 0);
            stationYbVo.setFPrecipitation((int) (fact12.getRain() + fact24.getRain()));
            StationYbDto stationYbDto = new StationYbDto();
            stationYbDto.setFState1(Integer.parseInt(weatherUtil.getWeatherId(fact12.getWeather1())));
            stationYbDto.setFState2(Integer.parseInt(weatherUtil.getWeatherId(fact24.getWeather1())));
            stationYbDto.setFWindDirection1(Integer.parseInt(weatherUtil.GetFxIDByValue(String.valueOf(fact12.getWindd()))));
            stationYbDto.setFWindDirection2(Integer.parseInt(weatherUtil.GetFxIDByValue(String.valueOf(fact24.getWindd()))));
            stationYbDto.setFTemperatureLow(fact12.getMintemp() < fact24.getMintemp() ? fact12.getMintemp() : fact24.getMintemp());
            stationYbDto.setFTemperatureHigh(fact12.getMaxtemp() > fact24.getMaxtemp() ? fact12.getMaxtemp() : fact24.getMaxtemp());
            stationYbDto.setFWindSpeedLow(fact12.getWinds());
            stationYbDto.setFWindSpeedHigh(fact24.getWinds());
            stationYbDto.setFWetnessLow((int) Math.round(fact12.getHumid()));
            stationYbDto.setFWetnessHigh((int) Math.round(fact24.getHumid()));
//            stationYbDto.setFPressure((int) (fact12.getPress()+fact24.getPress())/2);
            stationYbDto.setFCloudLow((int) Math.round(fact12.getCloudlow()));
            stationYbDto.setFCloudAll((int) Math.round(fact12.getCloud()));
            stationYbDto.setFPrecipitationrate((fact12.getRain() + fact24.getRain()) > 0 ? 100 : 0);
            stationYbDto.setFPrecipitation((int) (fact12.getRain() + fact24.getRain()));
            return SysResult.success(stationYbVo, stationYbDto);
        } else {
            return SysResult.success(new StationYbVo(), new StationYbDto());
        }
    }

    @ApiOperation("获取交通实况数据")
    @GetMapping("/getTrafficSmallScale")
    public SysResult getTrafficSmallScale(String observTime1, String observTime2, String stationId) {
        List<TrafficSmallScale> list = trafficSmallScaleService.listByParam(observTime1, observTime2, stationId);
        int avgPressCount = 0;
        int avgHumidCount = 0;
        int avgTempCount = 0;
        StationSkDto stationSkVo = new StationSkDto();
        for (int i = 0; i < list.size(); i++) {
            TrafficSmallScale sk = list.get(i);
            if (sk.getDrybulbtemp() > -65000) {
                if (i == 0) {
                    avgTempCount = Math.round(sk.getDrybulbtemp());
                } else {
                    avgTempCount += sk.getDrybulbtemp();
                }
            }
            if (sk.getMintemp() > -65000) {
                if (i == 0) {
                    stationSkVo.setTTemperatureLow(sk.getMintemp());
                } else if (sk.getMintemp() < stationSkVo.getTTemperatureLow()) {
                    stationSkVo.setTTemperatureLow(sk.getMintemp());
                }
            }
            if (sk.getMaxtemp() > -65000) {
                if (i == 0) {
                    stationSkVo.setTTemperatureHigh(sk.getMaxtemp());
                } else if (sk.getMaxtemp() > stationSkVo.getTTemperatureHigh()) {
                    stationSkVo.setTTemperatureHigh(sk.getMaxtemp());
                }
            }

            if (sk.getRain() > -65000) {
                if (i == 0) {
                    stationSkVo.setTPrecipitation24(Math.round(sk.getRain()));
                } else {
                    stationSkVo.setTPrecipitation24(stationSkVo.getTPrecipitation24() + sk.getRain());
                }
            }
            if (sk.getStationpress() > -65000) {
                if (i == 0) {
                    stationSkVo.setTPressure(Math.round(sk.getStationpress()));
                } else {
                    stationSkVo.setTPressure(stationSkVo.getTPressure() + sk.getStationpress());
                }
            }
            if (sk.getRelhumidity() > -65000) {
                if (i == 0) {
                    stationSkVo.setTWetness(sk.getRelhumidity());
                } else {
                    stationSkVo.setTWetness(stationSkVo.getTWetness() + sk.getRelhumidity());
                }
            }
        }
        //平均温度
        if (avgTempCount > 0) {
            stationSkVo.setTTemperature((double) avgTempCount / list.size());
        }
        //平均气压
        if (stationSkVo.getTPressure() > 0) {
            stationSkVo.setTPressure(stationSkVo.getTPressure() / list.size());
        }
        //平均相对湿度
        if (stationSkVo.getTWetness() > 0) {
            stationSkVo.setTWetness(stationSkVo.getTWetness() / list.size());
        }
        //求24小时变压
        if (list.size() > 0) {
            Float maxQY = list.get(list.size() - 1).getMaxStationPress();
            Float minQY = list.get(list.size() - 1).getMinStationPress();
            //压强存在
            if (maxQY > 0 || minQY > 0) {
                stationSkVo.setTIsallo(maxQY - minQY);//实况24小时变压
            }
        }
        //14小时风向
//        if ( list.size() > 0 ){
//            int windDirect = list.get(list.size()-1).getWinddirect();
//            if (windDirect >= 0 && windDirect <= 360) {
//                stationSkVo.setTWindDirection(windDirect);
//            }
//        }
        //实况平均总云量
        stationSkVo.setTCloudAll(0);
        return SysResult.success(stationSkVo, stationSkVo);
    }

    @ApiOperation("计算指数")
    @RequestMapping ("/calculateZhishu")
    public SysResult calculateZhishu(@RequestBody ZsjsDto zsjsDto) throws IOException, DocumentException, ParseException {
        List<SpecialSrvStation> stations = zsjsDto.getStations();
        List<StationSkDto> stationSkDtoList = zsjsDto.getStationSkDto();
        List<StationYbDto> stationYbDtoList = zsjsDto.getStationYbDto();

       // List<Object> all = new ArrayList<>();

        for (int i = 0; i < stations.size(); i++) {
            zsybService.calculate(zsjsDto.getDateChar(), zsjsDto.getTimeChar(), stations.get(i), stationYbDtoList.get(i), stationSkDtoList.get(i));
        }
        return SysResult.success();
    }


}
